package ch.nortgram.countdown_worldcup_2014.rss;

import java.io.IOException;
import java.net.URL;

import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;

import android.os.StrictMode;



public class Reader
	{
	public static Feed read(URL url) throws SAXException, IOException
		{
		StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
		StrictMode.setThreadPolicy(policy); 
		try {
			SAXParserFactory factory = SAXParserFactory.newInstance();
			SAXParser parser = factory.newSAXParser();
			XMLReader reader = parser.getXMLReader();
			Handler handler = new Handler();
			InputSource input = new InputSource(url.openStream());

			reader.setContentHandler(handler);
			reader.parse(input);

			return handler.getResult();
			}
		catch (ParserConfigurationException e)
			{
			throw new SAXException();
			}
		}
	}